public class DiameterOfBinaryTree {

    int ans = Integer.MIN_VALUE;
    public int diameterOfBinaryTree(TreeNode root) {
        process(root);
        return ans;
    }

    public int process(TreeNode node) {
        if (node == null) return 0;
        int l = process(node.left);
        int r = process(node.right);
        ans = Math.max(ans, l + r);
        return Math.max(l, r) + 1;
    }
}
